#include "widget.h"
#include "ui_widget.h"
#include <QFileDialog>
#include <QFile>
#include <QDebug>
#include <QDateTime>

Widget::Widget(QWidget *parent)
        : QWidget(parent), ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 点击选取文件按钮，弹出文件对话框
    connect(ui->pushButton, &QPushButton::clicked, [=]() {
        QString path = QFileDialog::getOpenFileName(this, "打开文件", "C:\\Users\\YANHAI\\Desktop");
        ui->lineEdit->setText(path);
        QFile file(path);
        file.open(QIODevice::ReadOnly);
        QByteArray array = file.readAll();
        ui->textEdit->setText(array);
        file.close();

        /// 文件信息 ///
        QFileInfo info(path);
        qDebug() << "大小：" << info.size() << "，后缀名：" << info.suffix() << "，文件名称：" << info.fileName() << "，文件路径：" << info.filePath();
        qDebug() << "创建日期：" << info.created().toString("yyyy/MM/dd hh:mm:ss");
        qDebug() << "最后修改日期：" << info.lastModified().toString("yyyy-MM-dd hh:mm:ss");
    });
}

Widget::~Widget()
{
    delete ui;
}

